export default app => {
  const { STRING, INTEGER, DATE, DataTypes } = app.Sequelize;

  const talent = app.model.define('talent', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    uuid: { type: STRING(36), unique: true },
    name: STRING(50),
    sex: INTEGER, // 0为女， 1为男
    tel: STRING(50),
    email: STRING(50),
    age: INTEGER,
    address: STRING(255),
    role: {
      type: DataTypes.STRING(36),
    }, // 职称
    post: {
      type: DataTypes.STRING(36),
    }, // 职务名
    education: STRING(10), // 学历
    unit: STRING(50), // 工作单位
    type: {
      type: DataTypes.STRING(36),
    }, // 工作单位性质
    fk_applicationArea: {
      type: DataTypes.STRING(36),
    }, // 行业领域
    fk_organization: {
      type: DataTypes.STRING(36),
    },
    pk_type: {
      type: DataTypes.STRING(36),
    }, // 人才类型（外键：talents_classfication）
    filler: {
      type: DataTypes.STRING(36),
    }, // 填写人
    description: DataTypes.TEXT, // 人才描述
    updateTime: DATE, // 更新日期
    createdAt: DATE,
    updatedAt: DATE,
  });
  talent.associate = () => {
    app.model.Talent.belongsToMany(app.model.Patent, {
      through: app.model.MergePatentTalent,
      foreignKey: 'talent_id',
      otherKey: 'patent_id',
    });
    app.model.Talent.belongsTo(app.model.ApplicationArea, {
      foreignKey: 'fk_applicationArea',
      targetKey: 'uuid',
    });
    app.model.Talent.belongsTo(app.model.Organization, {
      foreignKey: 'fk_organization',
      targetKey: 'uuid',
    });
    app.model.Talent.belongsTo(app.model.TalentClassfication, {
      foreignKey: 'pk_type',
      targetKey: 'uuid',
    });
    app.model.Talent.belongsTo(app.model.Title, {
      foreignKey: 'role',
      targetKey: 'uuid',
    });
    app.model.Talent.belongsTo(app.model.Position, {
      foreignKey: 'post',
      targetKey: 'uuid',
    });
    app.model.Talent.belongsTo(app.model.OrganizationType, {
      foreignKey: 'type',
      targetKey: 'uuid',
    });
  };

  return talent;
};
